/*
 * Desc: this is used to testing, all OpenBTS class can be used here
 * Author: ray1944
 */
#include <string.h>
#include "jwsmtp.h"
#include <stdio.h>
#include <sstream>
#include <GSMLogicalChannel.h>
#include <GSML3MMMessages.h>
#include "SMSControl.h"        
#include "ControlCommon.h"                                             
#include "TransactionTable.h"                                             
#include <Regexp.h>
using namespace std;                                                       
using namespace Control; 
#include "SMSMessages.h" 
using namespace SMS; 
#include "SIPInterface.h" 
#include "SIPUtility.h"     
#include "SIPMessage.h" 
#include "SIPEngine.h"                                                    
using namespace SIP; 
#include <Logger.h>                                                 
#undef WARNING 

void CPData_modifier()
{
    if (1)
    {
        unsigned reference = random() % 255;
        RPData rp_data;
        rp_data = RPData(reference, 
            RPAddress(gConfig.getStr("SMS.FakeSrcSMSC").c_str()), 
            TLDeliver("10086", "ok", 0)); 
        CPData deliver(15, rp_data); 
        RLFrame& rlframe = deliver.RPDU();                                                                               
        RLFrame seg1(UNDEFINED_PRIMITIVE, 7 * 8), seg2(UNDEFINED_PRIMITIVE, 4 * 8), seg3(UNDEFINED_PRIMITIVE, rlframe.size() - 11 * 8);
        //LOG(INFO) << "rlframe bits: " << rlframe.size();                                                               
        cerr<< "rlframe bits: " << rlframe.size() << endl;                                                               
        //LOG(INFO) << "rlframe bitstream: " << rlframe;                                                                 
        cerr << "rlframe bitstream: " << rlframe << endl;                                                                
        rlframe.segmentCopyTo(seg1, 0, 7 * 8);                                                                           
        rlframe.segmentCopyTo(seg2, 7*8, 4 * 8);                                                                         
        rlframe.segmentCopyTo(seg3, 11*8, rlframe.size() - 11 * 8);                                                      
        //LOG(INFO) << "segment 1: " << seg1;                                                                            
        cerr << "segment 1: " << seg1 << endl;                                                                           
        cerr << "segment 2: " << seg2 << endl;                                                                           
        cerr << "segment 3: " << seg3 << endl;                                                                           
        seg2.resize(2*8);                                                                                                
        seg2.fillField(0, strlen("10086"), 1*8);                                                                         
        seg2.fillField(1*8, 0, 1*8);                                                                                     
        cerr << "segment 2 after modify: "<<seg2<<endl;                                                                  
        rlframe.clone(seg1);                                                                                             
        rlframe.Append(seg2);                                                                                            
        rlframe.Append(seg3);                                                                                            
        cerr << "rlframe bitstream: "<< rlframe << endl;                                                                 
    }
}

void CPData_modfy2()
{
    std::string stream = "0791889623048015840D0A81903366410400080C4E2D65870055004300530032";
    char * bit[16] = {"0000", "0001", "0010", "0011",
                  "0100", "0101", "0110", "0111",
                  "1000", "1001", "1010", "1011",
                  "1100", "1101", "1110", "1111"
                 };
    int i = 0;
    std::string bStr;
    for (i = 0; i < stream.length(); i++)
    {
        char src = stream[i];

        //put pDst to bit[] binary 
        if (src >= '0' && src <= '9')
        {
            bStr.append(bit[src - '0']);
        }
        else
        {
            bStr.append(bit[src - 'A' + 10]);
        }
    }
    BitVector bvec(bStr.c_str());
    RLFrame seg(bvec, UNDEFINED_PRIMITIVE);
    cerr<< seg << endl;
}

void sendmail()
{
    jwsmtp::mailer mail("pcheng@rocketsoftware.com", "c_ogen@126.com", 
        "testing for jwsmtp", "testing content", "smtp.126.com", 
        jwsmtp::mailer::SMTP_PORT, false);
    mail.username("c_ogen@126.com");
    mail.password("1qaz2wsx");
    mail.operator()();
    cout << mail.response() << "\n";
}
